<!-- 账户汇总--结算收益明细 -->
<template>
  <div>
    <div class="table-page-search">
      <a-form>
        <a-form-item label="订单编号">
          <a-input v-model="queryParam.orderCode" placeholder="请输入订单编号" allowClear />
        </a-form-item>
        <a-form-item label="业务类型">
          <a-select v-model="queryParam.orderType" placeholder="请选择" allowClear>
            <a-select-option v-for="item in orderTypeDict" :key="item.value" :value="item.value">{{
              item.label
            }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="支付时间">
          <a-range-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="applyTime" class="width-25" />
        </a-form-item>
        <span class="search-submitButtons">
          <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
          <a-button @click="handleReset">重置</a-button>
        </span>
      </a-form>
    </div>
    <s-table
      ref="table"
      size="default"
      rowKey="id, enabled, title"
      :columns="columns"
      :data="loadData"
      :rowSelection="null"
    >
      <!-- 收益类型 -->
      <span slot="orderType" slot-scope="text">
        {{ orderTypeEnum[text]  }}
      </span>
      <!-- 收益类型 -->
      <span slot="earningType" slot-scope="text">
        <DictTag :options="Dict.getLocal('orderEarningTypeDict')" :value="text" isText />
      </span>

      <!-- 金额 -->
      <span slot="settAmount" slot-scope="text"> ￥{{ text }} </span>
    </s-table>
  </div>
</template>

<script>
import { STable } from '@/components'
import { SettList } from '@/api/finance/finance'
import { orderTypeEnum } from '@/enums/system'
import { orderTypeDict } from '@/api/order/order'
import DictTag from '@/components/DictTag'

export default {
  props: ['type'],
  components: {
    STable,
    DictTag
  },
  data() {
    return {
      queryParam: {
        orderCode: undefined, //订单号
        orderType: undefined, //订单类型
        startTime: undefined, //支付时间开始
        endTime: undefined, //支付时间结束
      },
      columns: [
        {
          title: '资金流水号',
          dataIndex: 'settleNo',
          width: '200px',
        },
        {
          title: '业务类型',
          dataIndex: 'orderType',
          ellipsis: true,
          width: '100px',
          scopedSlots: { customRender: 'orderType' },
        },
        {
          title: '收益类型',
          dataIndex: 'earningType',
          ellipsis: true,
          width: '100px',
          scopedSlots: { customRender: 'earningType' },
        },
        {
          title: '金额',
          dataIndex: 'settAmount',
          ellipsis: true,
          width: '100px',
          scopedSlots: { customRender: 'settAmount' },
        },
        {
          title: '支付时间',
          dataIndex: 'playAt',
          ellipsis: true,
          width: '150px',
        },
        {
          title: '分账时间',
          dataIndex: 'settledAt',
          ellipsis: true,
          width: '150px',
        },
        {
          title: '订单编号',
          dataIndex: 'orderCode',
          ellipsis: true,
          width: '150px',
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: async (parameter) => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize,
        }
        return SettList(Object.assign(params, this.queryParam))
          .then((res) => {
            if (res.code === 0) {
              return res
            } else {
              this.$message.error(res.msg)
            }
          })
          .catch((err) => {
            this.$message.error(err.msg)
          })
      },
      orderTypeEnum,
      orderTypeDict,
    }
  },
  computed: {
    applyTime: {
      get() {
        return [this.queryParam.startTime, this.queryParam.endTime]
      },
      set(val) {
        this.queryParam.startTime = val[0]
        this.queryParam.endTime = val[1]
      },
    },
  },
  created() {},
  methods: {
    handleReset() {
      Object.keys(this.queryParam).forEach((k) => {
        this.queryParam[k] = undefined
      })
      this.$refs.table.refresh(true)
    },
  },
}
</script>
<style scoped lang="less">
</style>
